package com.hurui.xiaoming.activity.opinion;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.hurui.xiaoming.R;
import com.hurui.xiaoming.activity.BaseActivity;
import com.hurui.xiaoming.bean.Li_UserMessageBack_Result;
import com.hurui.xiaoming.myconfig.PamaryKeys;
import com.hurui.xiaoming.utils.WriteReadSharedPrefs;

import java.util.HashMap;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class OpinionActivity extends BaseActivity {
    private TextView title_tv ;
    private ImageView back_iv ;
    private Button btnCommit;
    private Map<String,String> map;
    private final String TAG=this.getClass().getSimpleName();
    private String statu;
    private EditText content;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_opinion);
        map=new HashMap<>();
        initView();
        initAction();
    }

    @Override
    public void initView() {
        title_tv = (TextView) findViewById(R.id.top_title_tv);
        back_iv = (ImageView) findViewById(R.id.back_iv);
        btnCommit = ((Button) findViewById(R.id.commit_btn));
        content = ((EditText) findViewById(R.id.option_content));
        title_tv.setText("意见反馈");
    }

    @Override
    public void initAction() {
        back_iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                onFinish();
            }
        });
        btnCommit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (!TextUtils.isEmpty(content.getText().toString())){
                        map.put(PamaryKeys.UI_ID, WriteReadSharedPrefs.readUserID(mContext)+"");
                    map.put("fk_content",content.getText().toString());
                    apiSevice.onHttpDo_feedback(map).enqueue(new Callback<Li_UserMessageBack_Result>() {
                        @Override
                        public void onResponse(final Call<Li_UserMessageBack_Result> call, Response<Li_UserMessageBack_Result> response) {

                            onToast("你反馈的信息已提交");
                           runOnUiThread(new Runnable() {
                               @Override
                               public void run() {
                                   content.setText(null);

                               }
                           });

                        }

                        @Override
                        public void onFailure(Call<Li_UserMessageBack_Result> call, Throwable t) {
                            onToast("服务器连接错误,请稍后再试");
                        }
                    });
                }

            }
        });
    }


}
